home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #26 (Nov 87) / asm lab Formatter / DrawNumsInAString.asm next >
Assembly Source File  |  1987-10-21  |  2KB  |  85 lines

  1. ; DrawNumsInAString.asm
  2. ;-----------------------
  3. ; by Mike™ Scanlin  3 Jan 1987
  4.  
  5. Include Traps.D
  6.  
  7. Xref    DrawNumsInAString,NumToString,FixPtToString,FormNumString
  8. Xref    GetANumber
  9.  
  10. ;================
  11. DrawNumsInAString
  12. ;================
  13. ; draw a string that may contain implicit formatted numbers
  14. ;  input: stack contains numbers that will be needed and a pointer a
  15. ;      string. The numbers should be pushed on the stack in order
  16. ;      from last to first (so they can be poped off in order from
  17. ;      first to last). The last thing to be pushed on the stack 
  18. ;      is the string pointer
  19. ;       Each formatted number within the input string begins with
  20. ;      a '\' and then either an 'i' (for longints) or a 'f' (for
  21. ;      a fixed point number). For fixed points, first push the
  22. ;      fixed point number, then the divisor to be used to calculate
  23. ;      the remainder. The formatting after the 'i' or 'f' is the
  24. ;      same as for the FormNumString routine.
  25. ; output: a string is drawn
  26. ;      A0,D0 are trashed
  27.  
  28.     MOVEM.L        A0-A3/D1-D2,-(SP)
  29.     LEA        28(SP),A3    ;point to first parameter
  30.     MOVE.L        A3,-(SP)    ;save initial position
  31.     MOVE.L        (A3)+,A2    ;string pointer
  32. @1    MOVEQ        #0,D0
  33.     MOVE.B        (A2)+,D0
  34.     BEQ.S        @10        ;end of string found
  35.     CMPI.B        #'\',D0        ;is it a number?
  36.     BEQ.S        @2
  37.     MOVE        D0,-(SP)
  38.     _DrawChar
  39.     BRA.S        @1
  40. ;we got a number to format
  41. @2    LEA        scratch,A0
  42.     MOVE.B        (A2)+,D0
  43.     CMPI.B        #'i',D0        ;is it a longint?
  44.     BNE.S        @4
  45. ;handle integers
  46.     MOVE.L        (A3)+,D0    ;get longint
  47.     JSR        NumToString
  48.     BRA.S        @5        ;go format it
  49. @4    CMPI.B        #'f',D0        ;is it a fixed point?
  50.     BNE.S        @1        ;if not, ignore it
  51. ;handle fixed point
  52.     MOVEA.L        A2,A1
  53. ;find out how many decimal places should be passed to FixPtToString
  54.     MOVE.B        (A1)+,D0    ;skip comma, if present
  55.     CMPI.B        #',',D0
  56.     BEQ.S        @4.1
  57.     SUBA        #1,A1
  58. @4.1    JSR        GetANumber
  59.     BMI.S        @1        ;no quotient present
  60.     MOVE.B        (A1)+,D0
  61.     CMPI.B        #'.',D0
  62.     BNE.S        @4.2
  63.     JSR        GetANumber
  64.     MOVE        D0,D2
  65.     BPL.S        @4.3
  66. @4.2    MOVEQ        #0,D2        ;no remainder
  67. @4.3    MOVE        (A3)+,D1    ;get divisor
  68.     MOVE.L        (A3)+,D0    ;get fixed point num
  69.     JSR        FixPtToString
  70. ;do the formatting
  71. @5    MOVEA.L        A2,A1        ;addr of format string
  72.     JSR        FormNumString
  73.     MOVEA.L        A1,A2        ;point past format string
  74.     MOVE.L        A0,-(SP)
  75.     _DrawString
  76.     BRA.S        @1
  77. @10    SUBA.L        (SP)+,A3    ;calc len of params
  78.     MOVE        A3,D0
  79.     MOVEM.L        (SP)+,D1-D2/A0-A3
  80.     MOVE.L        (SP)+,A0    ;get return addr
  81.     ADDA        D0,SP        ;length of parameters
  82.     JMP        (A0)
  83.  
  84. scratch        DCB.B    40,0
  85.